package fr.mathis.ouestcharlie;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Window;

public class CongratzActivity extends SherlockActivity {

	static GameActivity listener;
	static CongratzActivity congratzScreen;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		if (getIntent().getExtras().getBoolean("showContinue")) {
			setContentView(R.layout.activity_congrats);

			TextView tv_next = (TextView) findViewById(R.id.next_button);
			tv_next.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					findViewById(R.id.second).setVisibility(View.VISIBLE);
					findViewById(R.id.first).setVisibility(View.GONE);
					
					new Launcher().execute();
				}
			});
		} else {
			setContentView(R.layout.activity_congrats_last);
		}

	}
	
	class Launcher extends AsyncTask<Void, Void, Void>
	{
		@Override
		protected Void doInBackground(Void... params) {
			return null;
		}
		
		@Override
		protected void onPostExecute(Void result) {
			super.onPostExecute(result);
			if(listener != null)
			{
				CongratzActivity.congratzScreen = CongratzActivity.this;
				listener.loadNextLevel();
			}
			else finish();
		}
	}
}
